package org.gdpu.model;

import javax.persistence.*;
import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: willson
 * Date: 13-10-31
 * Time: 上午10:34
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class BloodBank {

    /**
     * 编号
     */
    private int bloodBankId;
    /**
     * 血类型
     */
    private BloodType bloodType;
    /**
     * 献血量
     */
    private double bloodVolume;
    /**
     * 献血时间
     */
    private Date bloodDate;
    /**
     * 采血单位
     */
    private String department;
    /**
     * 献血人
     */
    private String bloodPerson;
    /**
     * 采血人
     */
    private String bloodCollection;
    /**
     * 到期时间
     */
    private Date overdue;
    /**
     * 状态
     * 0为未审核 1为未用 2为已用 3为报废
     */
    private int state;
    /**
     * 报废信息
     */
    private String message;
    /**
     * 血液成分
     */
    private BloodName bloodName;

    @Id
    @GeneratedValue
    public int getBloodBankId() {
        return bloodBankId;
    }

    public void setBloodBankId(int bloodBankId) {
        this.bloodBankId = bloodBankId;
    }

    @ManyToOne
    @JoinColumn(name = "bloodTypeId")
    public BloodType getBloodType() {
        return bloodType;
    }

    public void setBloodType(BloodType bloodType) {
        this.bloodType = bloodType;
    }

    public double getBloodVolume() {
        return bloodVolume;
    }

    public void setBloodVolume(double bloodVolume) {
        this.bloodVolume = bloodVolume;
    }

    @Temporal(TemporalType.DATE)
    public Date getBloodDate() {
        return bloodDate;
    }

    public void setBloodDate(Date bloodDate) {
        this.bloodDate = bloodDate;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(bloodDate);
        calendar.add(Calendar.DATE, 21);
        setOverdue(calendar.getTime());
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getBloodPerson() {
        return bloodPerson;
    }

    public void setBloodPerson(String bloodPerson) {
        this.bloodPerson = bloodPerson;
    }

    public String getBloodCollection() {
        return bloodCollection;
    }

    public void setBloodCollection(String bloodCollection) {
        this.bloodCollection = bloodCollection;
    }

    @Temporal(TemporalType.DATE)
    public Date getOverdue() {
        return overdue;
    }

    public void setOverdue(Date overdue) {
        this.overdue = overdue;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @ManyToOne
    @JoinColumn(name = "bloodName")
    public BloodName getBloodName() {
        return bloodName;
    }

    public void setBloodName(BloodName bloodName) {
        this.bloodName = bloodName;
    }
}
